home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume17 / gnugrep / part03 < prev    next >
Encoding:
Internet Message Format  |  1989-02-08  |  50.9 KB

  1. Subject:  v17i100:  Gnu E?GREP (it's fast), Part03/05
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Mike Haertel <mike@wheaties.ai.mit.edu>
  7. Posting-number: Volume 17, Issue 100
  8. Archive-name: gnugrep/part03
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of shell archive."
  17. # Contents:  regex.c
  18. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  19. if test -f 'regex.c' -a "${1}" != "-c" ; then 
  20.   echo shar: Will not clobber existing file \"'regex.c'\"
  21. else
  22. echo shar: Extracting \"'regex.c'\" \(49183 characters\)
  23. sed "s/^X//" >'regex.c' <<'END_OF_FILE'
  24. X/* Extended regular expression matching and search.
  25. X   Copyright (C) 1985 Free Software Foundation, Inc.
  26. X
  27. X               NO WARRANTY
  28. X
  29. X  BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
  30. XNO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
  31. XWHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
  32. XRICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
  33. XWITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
  34. XBUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  35. XFITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
  36. XAND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
  37. XDEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
  38. XCORRECTION.
  39. X
  40. X IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
  41. XSTALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
  42. XWHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
  43. XLIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
  44. XOTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
  45. XUSE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
  46. XDATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
  47. XA FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
  48. XPROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
  49. XDAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  50. X
  51. X        GENERAL PUBLIC LICENSE TO COPY
  52. X
  53. X  1. You may copy and distribute verbatim copies of this source file
  54. Xas you receive it, in any medium, provided that you conspicuously and
  55. Xappropriately publish on each copy a valid copyright notice "Copyright
  56. X(C) 1985 Free Software Foundation, Inc."; and include following the
  57. Xcopyright notice a verbatim copy of the above disclaimer of warranty
  58. Xand of this License.  You may charge a distribution fee for the
  59. Xphysical act of transferring a copy.
  60. X
  61. X  2. You may modify your copy or copies of this source file or
  62. Xany portion of it, and copy and distribute such modifications under
  63. Xthe terms of Paragraph 1 above, provided that you also do the following:
  64. X
  65. X    a) cause the modified files to carry prominent notices stating
  66. X    that you changed the files and the date of any change; and
  67. X
  68. X    b) cause the whole of any work that you distribute or publish,
  69. X    that in whole or in part contains or is a derivative of this
  70. X    program or any part thereof, to be licensed at no charge to all
  71. X    third parties on terms identical to those contained in this
  72. X    License Agreement (except that you may choose to grant more extensive
  73. X    warranty protection to some or all third parties, at your option).
  74. X
  75. X    c) You may charge a distribution fee for the physical act of
  76. X    transferring a copy, and you may at your option offer warranty
  77. X    protection in exchange for a fee.
  78. X
  79. XMere aggregation of another unrelated program with this program (or its
  80. Xderivative) on a volume of a storage or distribution medium does not bring
  81. Xthe other program under the scope of these terms.
  82. X
  83. X  3. You may copy and distribute this program (or a portion or derivative
  84. Xof it, under Paragraph 2) in object code or executable form under the terms
  85. Xof Paragraphs 1 and 2 above provided that you also do one of the following:
  86. X
  87. X    a) accompany it with the complete corresponding machine-readable
  88. X    source code, which must be distributed under the terms of
  89. X    Paragraphs 1 and 2 above; or,
  90. X
  91. X    b) accompany it with a written offer, valid for at least three
  92. X    years, to give any third party free (except for a nominal
  93. X    shipping charge) a complete machine-readable copy of the
  94. X    corresponding source code, to be distributed under the terms of
  95. X    Paragraphs 1 and 2 above; or,
  96. X
  97. X    c) accompany it with the information you received as to where the
  98. X    corresponding source code may be obtained.  (This alternative is
  99. X    allowed only for noncommercial distribution and only if you
  100. X    received the program in object code or executable form alone.)
  101. X
  102. XFor an executable file, complete source code means all the source code for
  103. Xall modules it contains; but, as a special exception, it need not include
  104. Xsource code for modules which are standard libraries that accompany the
  105. Xoperating system on which the executable file runs.
  106. X
  107. X  4. You may not copy, sublicense, distribute or transfer this program
  108. Xexcept as expressly provided under this License Agreement.  Any attempt
  109. Xotherwise to copy, sublicense, distribute or transfer this program is void and
  110. Xyour rights to use the program under this License agreement shall be
  111. Xautomatically terminated.  However, parties who have received computer
  112. Xsoftware programs from you with this License Agreement will not have
  113. Xtheir licenses terminated so long as such parties remain in full compliance.
  114. X
  115. X  5. If you wish to incorporate parts of this program into other free
  116. Xprograms whose distribution conditions are different, write to the Free
  117. XSoftware Foundation at 675 Mass Ave, Cambridge, MA 02139.  We have not yet
  118. Xworked out a simple rule that can be stated here, but we will often permit
  119. Xthis.  We will be guided by the two goals of preserving the free status of
  120. Xall derivatives of our free software and of promoting the sharing and reuse of
  121. Xsoftware.
  122. X
  123. X
  124. XIn other words, you are welcome to use, share and improve this program.
  125. XYou are forbidden to forbid anyone else to use, share and improve
  126. Xwhat you give them.   Help stamp out software-hoarding!  */
  127. X
  128. X
  129. X/* To test, compile with -Dtest.
  130. X This Dtestable feature turns this into a self-contained program
  131. X which reads a pattern, describes how it compiles,
  132. X then reads a string and searches for it.  */
  133. X
  134. X#ifdef emacs
  135. X
  136. X/* The `emacs' switch turns on certain special matching commands
  137. X that make sense only in emacs. */
  138. X
  139. X#include "config.h"
  140. X#include "lisp.h"
  141. X#include "buffer.h"
  142. X#include "syntax.h"
  143. X
  144. X#else  /* not emacs */
  145. X
  146. X#ifdef USG
  147. X#define bcopy(s,d,n)    memcpy((d),(s),(n))
  148. X#define bcmp(s1,s2,n)    memcmp((s1),(s2),(n))
  149. X#define bzero(s,n)    memset((s),0,(n))
  150. X#endif
  151. X
  152. X/* Make alloca work the best possible way.  */
  153. X#ifdef __GNUC__
  154. X#define alloca __builtin_alloca
  155. X#else
  156. X#ifdef sparc
  157. X#include <alloca.h>
  158. X#endif
  159. X#endif
  160. X
  161. X/*
  162. X * Define the syntax stuff, so we can do the \<...\> things.
  163. X */
  164. X
  165. X#ifndef Sword /* must be non-zero in some of the tests below... */
  166. X#define Sword 1
  167. X#endif
  168. X
  169. X#define SYNTAX(c) re_syntax_table[c]
  170. X
  171. X#ifdef SYNTAX_TABLE
  172. X
  173. Xchar *re_syntax_table;
  174. X
  175. X#else
  176. X
  177. Xstatic char re_syntax_table[256];
  178. X
  179. Xstatic void
  180. Xinit_syntax_once ()
  181. X{
  182. X   register int c;
  183. X   static int done = 0;
  184. X
  185. X   if (done)
  186. X     return;
  187. X
  188. X   bzero (re_syntax_table, sizeof re_syntax_table);
  189. X
  190. X   for (c = 'a'; c <= 'z'; c++)
  191. X     re_syntax_table[c] = Sword;
  192. X
  193. X   for (c = 'A'; c <= 'Z'; c++)
  194. X     re_syntax_table[c] = Sword;
  195. X
  196. X   for (c = '0'; c <= '9'; c++)
  197. X     re_syntax_table[c] = Sword;
  198. X
  199. X   done = 1;
  200. X}
  201. X
  202. X#endif /* SYNTAX_TABLE */
  203. X#endif /* not emacs */
  204. X
  205. X#include "regex.h"
  206. X
  207. X/* Number of failure points to allocate space for initially,
  208. X when matching.  If this number is exceeded, more space is allocated,
  209. X so it is not a hard limit.  */
  210. X
  211. X#ifndef NFAILURES
  212. X#define NFAILURES 80
  213. X#endif /* NFAILURES */
  214. X
  215. X/* width of a byte in bits */
  216. X
  217. X#define BYTEWIDTH 8
  218. X
  219. X#ifndef SIGN_EXTEND_CHAR
  220. X#define SIGN_EXTEND_CHAR(x) (x)
  221. X#endif
  222. X
  223. Xstatic int obscure_syntax = 0;
  224. X
  225. X/* Specify the precise syntax of regexp for compilation.
  226. X   This provides for compatibility for various utilities
  227. X   which historically have different, incompatible syntaxes.
  228. X
  229. X   The argument SYNTAX is a bit-mask containing the two bits
  230. X   RE_NO_BK_PARENS and RE_NO_BK_VBAR.  */
  231. X
  232. Xint
  233. Xre_set_syntax (syntax)
  234. X{
  235. X  int ret;
  236. X
  237. X  ret = obscure_syntax;
  238. X  obscure_syntax = syntax;
  239. X  return ret;
  240. X}
  241. X
  242. X/* re_compile_pattern takes a regular-expression string
  243. X   and converts it into a buffer full of byte commands for matching.
  244. X
  245. X  PATTERN   is the address of the pattern string
  246. X  SIZE      is the length of it.
  247. X  BUFP        is a  struct re_pattern_buffer *  which points to the info
  248. X        on where to store the byte commands.
  249. X        This structure contains a  char *  which points to the
  250. X        actual space, which should have been obtained with malloc.
  251. X        re_compile_pattern may use  realloc  to grow the buffer space.
  252. X
  253. X  The number of bytes of commands can be found out by looking in
  254. X  the  struct re_pattern_buffer  that bufp pointed to,
  255. X  after re_compile_pattern returns.
  256. X*/
  257. X
  258. X#define PATPUSH(ch) (*b++ = (char) (ch))
  259. X
  260. X#define PATFETCH(c) \
  261. X {if (p == pend) goto end_of_pattern; \
  262. X  c = * (unsigned char *) p++; \
  263. X  if (translate) c = translate[c]; }
  264. X
  265. X#define PATFETCH_RAW(c) \
  266. X {if (p == pend) goto end_of_pattern; \
  267. X  c = * (unsigned char *) p++; }
  268. X
  269. X#define PATUNFETCH p--
  270. X
  271. X#define EXTEND_BUFFER \
  272. X  { char *old_buffer = bufp->buffer; \
  273. X    if (bufp->allocated == (1<<16)) goto too_big; \
  274. X    bufp->allocated *= 2; \
  275. X    if (bufp->allocated > (1<<16)) bufp->allocated = (1<<16); \
  276. X    if (!(bufp->buffer = (char *) realloc (bufp->buffer, bufp->allocated))) \
  277. X      goto memory_exhausted; \
  278. X    c = bufp->buffer - old_buffer; \
  279. X    b += c; \
  280. X    if (fixup_jump) \
  281. X      fixup_jump += c; \
  282. X    if (laststart) \
  283. X      laststart += c; \
  284. X    begalt += c; \
  285. X    if (pending_exact) \
  286. X      pending_exact += c; \
  287. X  }
  288. X
  289. Xstatic int store_jump (), insert_jump ();
  290. X
  291. Xchar *
  292. Xre_compile_pattern (pattern, size, bufp)
  293. X     char *pattern;
  294. X     int size;
  295. X     struct re_pattern_buffer *bufp;
  296. X{
  297. X  register char *b = bufp->buffer;
  298. X  register char *p = pattern;
  299. X  char *pend = pattern + size;
  300. X  register unsigned c, c1;
  301. X  char *p1;
  302. X  unsigned char *translate = (unsigned char *) bufp->translate;
  303. X
  304. X  /* address of the count-byte of the most recently inserted "exactn" command.
  305. X    This makes it possible to tell whether a new exact-match character
  306. X    can be added to that command or requires a new "exactn" command. */
  307. X     
  308. X  char *pending_exact = 0;
  309. X
  310. X  /* address of the place where a forward-jump should go
  311. X    to the end of the containing expression.
  312. X    Each alternative of an "or", except the last, ends with a forward-jump
  313. X    of this sort. */
  314. X
  315. X  char *fixup_jump = 0;
  316. X
  317. X  /* address of start of the most recently finished expression.
  318. X    This tells postfix * where to find the start of its operand. */
  319. X
  320. X  char *laststart = 0;
  321. X
  322. X  /* In processing a repeat, 1 means zero matches is allowed */
  323. X
  324. X  char zero_times_ok;
  325. X
  326. X  /* In processing a repeat, 1 means many matches is allowed */
  327. X
  328. X  char many_times_ok;
  329. X
  330. X  /* address of beginning of regexp, or inside of last \( */
  331. X
  332. X  char *begalt = b;
  333. X
  334. X  /* Stack of information saved by \( and restored by \).
  335. X     Four stack elements are pushed by each \(:
  336. X       First, the value of b.
  337. X       Second, the value of fixup_jump.
  338. X       Third, the value of regnum.
  339. X       Fourth, the value of begalt.  */
  340. X
  341. X  int stackb[40];
  342. X  int *stackp = stackb;
  343. X  int *stacke = stackb + 40;
  344. X  int *stackt;
  345. X
  346. X  /* Counts \('s as they are encountered.  Remembered for the matching \),
  347. X     where it becomes the "register number" to put in the stop_memory command */
  348. X
  349. X  int regnum = 1;
  350. X
  351. X  bufp->fastmap_accurate = 0;
  352. X
  353. X#ifndef emacs
  354. X#ifndef SYNTAX_TABLE
  355. X  /*
  356. X   * Initialize the syntax table.
  357. X   */
  358. X   init_syntax_once();
  359. X#endif
  360. X#endif
  361. X
  362. X  if (bufp->allocated == 0)
  363. X    {
  364. X      bufp->allocated = 28;
  365. X      if (bufp->buffer)
  366. X    /* EXTEND_BUFFER loses when bufp->allocated is 0 */
  367. X    bufp->buffer = (char *) realloc (bufp->buffer, 28);
  368. X      else
  369. X    /* Caller did not allocate a buffer.  Do it for him */
  370. X    bufp->buffer = (char *) malloc (28);
  371. X      if (!bufp->buffer) goto memory_exhausted;
  372. X      begalt = b = bufp->buffer;
  373. X    }
  374. X
  375. X  while (p != pend)
  376. X    {
  377. X      if (b - bufp->buffer > bufp->allocated - 10)
  378. X    /* Note that EXTEND_BUFFER clobbers c */
  379. X    EXTEND_BUFFER;
  380. X
  381. X      PATFETCH (c);
  382. X
  383. X      switch (c)
  384. X    {
  385. X    case '$':
  386. X      if (obscure_syntax & RE_TIGHT_VBAR)
  387. X        {
  388. X          if (! (obscure_syntax & RE_CONTEXT_INDEP_OPS) && p != pend)
  389. X        goto normal_char;
  390. X          /* Make operand of last vbar end before this `$'.  */
  391. X          if (fixup_jump)
  392. X        store_jump (fixup_jump, jump, b);
  393. X          fixup_jump = 0;
  394. X          PATPUSH (endline);
  395. X          break;
  396. X        }
  397. X
  398. X      /* $ means succeed if at end of line, but only in special contexts.
  399. X        If randomly in the middle of a pattern, it is a normal character. */
  400. X      if (p == pend || *p == '\n'
  401. X          || (obscure_syntax & RE_CONTEXT_INDEP_OPS)
  402. X          || (obscure_syntax & RE_NO_BK_PARENS
  403. X          ? *p == ')'
  404. X          : *p == '\\' && p[1] == ')')
  405. X          || (obscure_syntax & RE_NO_BK_VBAR
  406. X          ? *p == '|'
  407. X          : *p == '\\' && p[1] == '|'))
  408. X        {
  409. X          PATPUSH (endline);
  410. X          break;
  411. X        }
  412. X      goto normal_char;
  413. X
  414. X    case '^':
  415. X      /* ^ means succeed if at beg of line, but only if no preceding pattern. */
  416. X
  417. X      if (laststart && p[-2] != '\n'
  418. X          && ! (obscure_syntax & RE_CONTEXT_INDEP_OPS))
  419. X        goto normal_char;
  420. X      if (obscure_syntax & RE_TIGHT_VBAR)
  421. X        {
  422. X          if (p != pattern + 1
  423. X          && ! (obscure_syntax & RE_CONTEXT_INDEP_OPS))
  424. X        goto normal_char;
  425. X          PATPUSH (begline);
  426. X          begalt = b;
  427. X        }
  428. X      else
  429. X        PATPUSH (begline);
  430. X      break;
  431. X
  432. X    case '+':
  433. X    case '?':
  434. X      if (obscure_syntax & RE_BK_PLUS_QM)
  435. X        goto normal_char;
  436. X    handle_plus:
  437. X    case '*':
  438. X      /* If there is no previous pattern, char not special. */
  439. X      if (!laststart && ! (obscure_syntax & RE_CONTEXT_INDEP_OPS))
  440. X        goto normal_char;
  441. X      /* If there is a sequence of repetition chars,
  442. X         collapse it down to equivalent to just one.  */
  443. X      zero_times_ok = 0;
  444. X      many_times_ok = 0;
  445. X      while (1)
  446. X        {
  447. X          zero_times_ok |= c != '+';
  448. X          many_times_ok |= c != '?';
  449. X          if (p == pend)
  450. X        break;
  451. X          PATFETCH (c);
  452. X          if (c == '*')
  453. X        ;
  454. X          else if (!(obscure_syntax & RE_BK_PLUS_QM)
  455. X               && (c == '+' || c == '?'))
  456. X        ;
  457. X          else if ((obscure_syntax & RE_BK_PLUS_QM)
  458. X               && c == '\\')
  459. X        {
  460. X          int c1;
  461. X          PATFETCH (c1);
  462. X          if (!(c1 == '+' || c1 == '?'))
  463. X            {
  464. X              PATUNFETCH;
  465. X              PATUNFETCH;
  466. X              break;
  467. X            }
  468. X          c = c1;
  469. X        }
  470. X          else
  471. X        {
  472. X          PATUNFETCH;
  473. X          break;
  474. X        }
  475. X        }
  476. X
  477. X      /* Star, etc. applied to an empty pattern is equivalent
  478. X         to an empty pattern.  */
  479. X      if (!laststart)
  480. X        break;
  481. X
  482. X      /* Now we know whether 0 matches is allowed,
  483. X         and whether 2 or more matches is allowed.  */
  484. X      if (many_times_ok)
  485. X        {
  486. X          /* If more than one repetition is allowed,
  487. X         put in a backward jump at the end.  */
  488. X          store_jump (b, maybe_finalize_jump, laststart - 3);
  489. X          b += 3;
  490. X        }
  491. X      insert_jump (on_failure_jump, laststart, b + 3, b);
  492. X      pending_exact = 0;
  493. X      b += 3;
  494. X      if (!zero_times_ok)
  495. X        {
  496. X          /* At least one repetition required: insert before the loop
  497. X         a skip over the initial on-failure-jump instruction */
  498. X          insert_jump (dummy_failure_jump, laststart, laststart + 6, b);
  499. X          b += 3;
  500. X        }
  501. X      break;
  502. X
  503. X    case '.':
  504. X      laststart = b;
  505. X      PATPUSH (anychar);
  506. X      break;
  507. X
  508. X    case '[':
  509. X      while (b - bufp->buffer
  510. X         > bufp->allocated - 3 - (1 << BYTEWIDTH) / BYTEWIDTH)
  511. X        /* Note that EXTEND_BUFFER clobbers c */
  512. X        EXTEND_BUFFER;
  513. X
  514. X      laststart = b;
  515. X      if (*p == '^')
  516. X        PATPUSH (charset_not), p++;
  517. X      else
  518. X        PATPUSH (charset);
  519. X      p1 = p;
  520. X
  521. X      PATPUSH ((1 << BYTEWIDTH) / BYTEWIDTH);
  522. X      /* Clear the whole map */
  523. X      bzero (b, (1 << BYTEWIDTH) / BYTEWIDTH);
  524. X      /* Read in characters and ranges, setting map bits */
  525. X      while (1)
  526. X        {
  527. X          PATFETCH (c);
  528. X          if (c == ']' && p != p1 + 1) break;
  529. X          if (*p == '-' && p[1] != ']')
  530. X        {
  531. X          PATFETCH (c1);
  532. X          PATFETCH (c1);
  533. X          while (c <= c1)
  534. X            b[c / BYTEWIDTH] |= 1 << (c % BYTEWIDTH), c++;
  535. X        }
  536. X          else
  537. X        {
  538. X          b[c / BYTEWIDTH] |= 1 << (c % BYTEWIDTH);
  539. X        }
  540. X        }
  541. X      /* Discard any bitmap bytes that are all 0 at the end of the map.
  542. X         Decrement the map-length byte too. */
  543. X      while ((int) b[-1] > 0 && b[b[-1] - 1] == 0)
  544. X        b[-1]--;
  545. X      b += b[-1];
  546. X      break;
  547. X
  548. X    case '(':
  549. X      if (! (obscure_syntax & RE_NO_BK_PARENS))
  550. X        goto normal_char;
  551. X      else
  552. X        goto handle_open;
  553. X
  554. X    case ')':
  555. X      if (! (obscure_syntax & RE_NO_BK_PARENS))
  556. X        goto normal_char;
  557. X      else
  558. X        goto handle_close;
  559. X
  560. X    case '\n':
  561. X      if (! (obscure_syntax & RE_NEWLINE_OR))
  562. X        goto normal_char;
  563. X      else
  564. X        goto handle_bar;
  565. X
  566. X    case '|':
  567. X      if (! (obscure_syntax & RE_NO_BK_VBAR))
  568. X        goto normal_char;
  569. X      else
  570. X        goto handle_bar;
  571. X
  572. X        case '\\':
  573. X      if (p == pend) goto invalid_pattern;
  574. X      PATFETCH_RAW (c);
  575. X      switch (c)
  576. X        {
  577. X        case '(':
  578. X          if (obscure_syntax & RE_NO_BK_PARENS)
  579. X        goto normal_backsl;
  580. X        handle_open:
  581. X          if (stackp == stacke) goto nesting_too_deep;
  582. X          if (regnum < RE_NREGS)
  583. X            {
  584. X          PATPUSH (start_memory);
  585. X          PATPUSH (regnum);
  586. X            }
  587. X          *stackp++ = b - bufp->buffer;
  588. X          *stackp++ = fixup_jump ? fixup_jump - bufp->buffer + 1 : 0;
  589. X          *stackp++ = regnum++;
  590. X          *stackp++ = begalt - bufp->buffer;
  591. X          fixup_jump = 0;
  592. X          laststart = 0;
  593. X          begalt = b;
  594. X          break;
  595. X
  596. X        case ')':
  597. X          if (obscure_syntax & RE_NO_BK_PARENS)
  598. X        goto normal_backsl;
  599. X        handle_close:
  600. X          if (stackp == stackb) goto unmatched_close;
  601. X          begalt = *--stackp + bufp->buffer;
  602. X          if (fixup_jump)
  603. X        store_jump (fixup_jump, jump, b);
  604. X          if (stackp[-1] < RE_NREGS)
  605. X        {
  606. X          PATPUSH (stop_memory);
  607. X          PATPUSH (stackp[-1]);
  608. X        }
  609. X          stackp -= 2;
  610. X          fixup_jump = 0;
  611. X          if (*stackp)
  612. X        fixup_jump = *stackp + bufp->buffer - 1;
  613. X          laststart = *--stackp + bufp->buffer;
  614. X          break;
  615. X
  616. X        case '|':
  617. X          if (obscure_syntax & RE_NO_BK_VBAR)
  618. X        goto normal_backsl;
  619. X        handle_bar:
  620. X          insert_jump (on_failure_jump, begalt, b + 6, b);
  621. X          pending_exact = 0;
  622. X          b += 3;
  623. X          if (fixup_jump)
  624. X        store_jump (fixup_jump, jump, b);
  625. X          fixup_jump = b;
  626. X          b += 3;
  627. X          laststart = 0;
  628. X          begalt = b;
  629. X          break;
  630. X
  631. X#ifdef emacs
  632. X        case '=':
  633. X          PATPUSH (at_dot);
  634. X          break;
  635. X
  636. X        case 's':    
  637. X          laststart = b;
  638. X          PATPUSH (syntaxspec);
  639. X          PATFETCH (c);
  640. X          PATPUSH (syntax_spec_code[c]);
  641. X          break;
  642. X
  643. X        case 'S':
  644. X          laststart = b;
  645. X          PATPUSH (notsyntaxspec);
  646. X          PATFETCH (c);
  647. X          PATPUSH (syntax_spec_code[c]);
  648. X          break;
  649. X#endif /* emacs */
  650. X
  651. X        case 'w':
  652. X          laststart = b;
  653. X          PATPUSH (wordchar);
  654. X          break;
  655. X
  656. X        case 'W':
  657. X          laststart = b;
  658. X          PATPUSH (notwordchar);
  659. X          break;
  660. X
  661. X        case '<':
  662. X          PATPUSH (wordbeg);
  663. X          break;
  664. X
  665. X        case '>':
  666. X          PATPUSH (wordend);
  667. X          break;
  668. X
  669. X        case 'b':
  670. X          PATPUSH (wordbound);
  671. X          break;
  672. X
  673. X        case 'B':
  674. X          PATPUSH (notwordbound);
  675. X          break;
  676. X
  677. X        case '`':
  678. X          PATPUSH (begbuf);
  679. X          break;
  680. X
  681. X        case '\'':
  682. X          PATPUSH (endbuf);
  683. X          break;
  684. X
  685. X        case '1':
  686. X        case '2':
  687. X        case '3':
  688. X        case '4':
  689. X        case '5':
  690. X        case '6':
  691. X        case '7':
  692. X        case '8':
  693. X        case '9':
  694. X          c1 = c - '0';
  695. X          if (c1 >= regnum)
  696. X        goto normal_char;
  697. X          for (stackt = stackp - 2;  stackt > stackb;  stackt -= 4)
  698. X         if (*stackt == c1)
  699. X          goto normal_char;
  700. X          laststart = b;
  701. X          PATPUSH (duplicate);
  702. X          PATPUSH (c1);
  703. X          break;
  704. X
  705. X        case '+':
  706. X        case '?':
  707. X          if (obscure_syntax & RE_BK_PLUS_QM)
  708. X        goto handle_plus;
  709. X
  710. X        default:
  711. X        normal_backsl:
  712. X          /* You might think it would be useful for \ to mean
  713. X         not to translate; but if we don't translate it
  714. X         it will never match anything.  */
  715. X          if (translate) c = translate[c];
  716. X          goto normal_char;
  717. X        }
  718. X      break;
  719. X
  720. X    default:
  721. X    normal_char:
  722. X      if (!pending_exact || pending_exact + *pending_exact + 1 != b
  723. X          || *pending_exact == 0177 || *p == '*' || *p == '^'
  724. X          || ((obscure_syntax & RE_BK_PLUS_QM)
  725. X          ? *p == '\\' && (p[1] == '+' || p[1] == '?')
  726. X          : (*p == '+' || *p == '?')))
  727. X        {
  728. X          laststart = b;
  729. X          PATPUSH (exactn);
  730. X          pending_exact = b;
  731. X          PATPUSH (0);
  732. X        }
  733. X      PATPUSH (c);
  734. X      (*pending_exact)++;
  735. X    }
  736. X    }
  737. X
  738. X  if (fixup_jump)
  739. X    store_jump (fixup_jump, jump, b);
  740. X
  741. X  if (stackp != stackb) goto unmatched_open;
  742. X
  743. X  bufp->used = b - bufp->buffer;
  744. X  return 0;
  745. X
  746. X invalid_pattern:
  747. X  return "Invalid regular expression";
  748. X
  749. X unmatched_open:
  750. X  return "Unmatched \\(";
  751. X
  752. X unmatched_close:
  753. X  return "Unmatched \\)";
  754. X
  755. X end_of_pattern:
  756. X  return "Premature end of regular expression";
  757. X
  758. X nesting_too_deep:
  759. X  return "Nesting too deep";
  760. X
  761. X too_big:
  762. X  return "Regular expression too big";
  763. X
  764. X memory_exhausted:
  765. X  return "Memory exhausted";
  766. X}
  767. X
  768. X/* Store where `from' points a jump operation to jump to where `to' points.
  769. X  `opcode' is the opcode to store. */
  770. X
  771. Xstatic int
  772. Xstore_jump (from, opcode, to)
  773. X     char *from, *to;
  774. X     char opcode;
  775. X{
  776. X  from[0] = opcode;
  777. X  from[1] = (to - (from + 3)) & 0377;
  778. X  from[2] = (to - (from + 3)) >> 8;
  779. X}
  780. X
  781. X/* Open up space at char FROM, and insert there a jump to TO.
  782. X   CURRENT_END gives te end of the storage no in use,
  783. X   so we know how much data to copy up.
  784. X   OP is the opcode of the jump to insert.
  785. X
  786. X   If you call this function, you must zero out pending_exact.  */
  787. X
  788. Xstatic int
  789. Xinsert_jump (op, from, to, current_end)
  790. X     char op;
  791. X     char *from, *to, *current_end;
  792. X{
  793. X  register char *pto = current_end + 3;
  794. X  register char *pfrom = current_end;
  795. X  while (pfrom != from)
  796. X    *--pto = *--pfrom;
  797. X  store_jump (from, op, to);
  798. X}
  799. X
  800. X/* Given a pattern, compute a fastmap from it.
  801. X The fastmap records which of the (1 << BYTEWIDTH) possible characters
  802. X can start a string that matches the pattern.
  803. X This fastmap is used by re_search to skip quickly over totally implausible text.
  804. X
  805. X The caller must supply the address of a (1 << BYTEWIDTH)-byte data area
  806. X as bufp->fastmap.
  807. X The other components of bufp describe the pattern to be used.  */
  808. X
  809. Xvoid
  810. Xre_compile_fastmap (bufp)
  811. X     struct re_pattern_buffer *bufp;
  812. X{
  813. X  unsigned char *pattern = (unsigned char *) bufp->buffer;
  814. X  int size = bufp->used;
  815. X  register char *fastmap = bufp->fastmap;
  816. X  register unsigned char *p = pattern;
  817. X  register unsigned char *pend = pattern + size;
  818. X  register int j, k;
  819. X  unsigned char *translate = (unsigned char *) bufp->translate;
  820. X
  821. X  unsigned char *stackb[NFAILURES];
  822. X  unsigned char **stackp = stackb;
  823. X
  824. X  bzero (fastmap, (1 << BYTEWIDTH));
  825. X  bufp->fastmap_accurate = 1;
  826. X  bufp->can_be_null = 0;
  827. X      
  828. X  while (p)
  829. X    {
  830. X      if (p == pend)
  831. X    {
  832. X      bufp->can_be_null = 1;
  833. X      break;
  834. X    }
  835. X#ifdef SWITCH_ENUM_BUG
  836. X      switch ((int) ((enum regexpcode) *p++))
  837. X#else
  838. X      switch ((enum regexpcode) *p++)
  839. X#endif
  840. X    {
  841. X    case exactn:
  842. X      if (translate)
  843. X        fastmap[translate[p[1]]] = 1;
  844. X      else
  845. X        fastmap[p[1]] = 1;
  846. X      break;
  847. X
  848. X        case begline:
  849. X        case before_dot:
  850. X    case at_dot:
  851. X    case after_dot:
  852. X    case begbuf:
  853. X    case endbuf:
  854. X    case wordbound:
  855. X    case notwordbound:
  856. X    case wordbeg:
  857. X    case wordend:
  858. X      continue;
  859. X
  860. X    case endline:
  861. X      if (translate)
  862. X        fastmap[translate['\n']] = 1;
  863. X      else
  864. X        fastmap['\n'] = 1;
  865. X      if (bufp->can_be_null != 1)
  866. X        bufp->can_be_null = 2;
  867. X      break;
  868. X
  869. X    case finalize_jump:
  870. X    case maybe_finalize_jump:
  871. X    case jump:
  872. X    case dummy_failure_jump:
  873. X      bufp->can_be_null = 1;
  874. X      j = *p++ & 0377;
  875. X      j += SIGN_EXTEND_CHAR (*(char *)p) << 8;
  876. X      p += j + 1;        /* The 1 compensates for missing ++ above */
  877. X      if (j > 0)
  878. X        continue;
  879. X      /* Jump backward reached implies we just went through
  880. X         the body of a loop and matched nothing.
  881. X         Opcode jumped to should be an on_failure_jump.
  882. X         Just treat it like an ordinary jump.
  883. X         For a * loop, it has pushed its failure point already;
  884. X         if so, discard that as redundant.  */
  885. X      if ((enum regexpcode) *p != on_failure_jump)
  886. X        continue;
  887. X      p++;
  888. X      j = *p++ & 0377;
  889. X      j += SIGN_EXTEND_CHAR (*(char *)p) << 8;
  890. X      p += j + 1;        /* The 1 compensates for missing ++ above */
  891. X      if (stackp != stackb && *stackp == p)
  892. X        stackp--;
  893. X      continue;
  894. X      
  895. X    case on_failure_jump:
  896. X      j = *p++ & 0377;
  897. X      j += SIGN_EXTEND_CHAR (*(char *)p) << 8;
  898. X      p++;
  899. X      *++stackp = p + j;
  900. X      continue;
  901. X
  902. X    case start_memory:
  903. X    case stop_memory:
  904. X      p++;
  905. X      continue;
  906. X
  907. X    case duplicate:
  908. X      bufp->can_be_null = 1;
  909. X      fastmap['\n'] = 1;
  910. X    case anychar:
  911. X      for (j = 0; j < (1 << BYTEWIDTH); j++)
  912. X        if (j != '\n')
  913. X          fastmap[j] = 1;
  914. X      if (bufp->can_be_null)
  915. X        return;
  916. X      /* Don't return; check the alternative paths
  917. X         so we can set can_be_null if appropriate.  */
  918. X      break;
  919. X
  920. X    case wordchar:
  921. X      for (j = 0; j < (1 << BYTEWIDTH); j++)
  922. X        if (SYNTAX (j) == Sword)
  923. X          fastmap[j] = 1;
  924. X      break;
  925. X
  926. X    case notwordchar:
  927. X      for (j = 0; j < (1 << BYTEWIDTH); j++)
  928. X        if (SYNTAX (j) != Sword)
  929. X          fastmap[j] = 1;
  930. X      break;
  931. X
  932. X#ifdef emacs
  933. X    case syntaxspec:
  934. X      k = *p++;
  935. X      for (j = 0; j < (1 << BYTEWIDTH); j++)
  936. X        if (SYNTAX (j) == (enum syntaxcode) k)
  937. X          fastmap[j] = 1;
  938. X      break;
  939. X
  940. X    case notsyntaxspec:
  941. X      k = *p++;
  942. X      for (j = 0; j < (1 << BYTEWIDTH); j++)
  943. X        if (SYNTAX (j) != (enum syntaxcode) k)
  944. X          fastmap[j] = 1;
  945. X      break;
  946. X#endif /* emacs */
  947. X
  948. X    case charset:
  949. X      for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--)
  950. X        if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH)))
  951. X          {
  952. X        if (translate)
  953. X          fastmap[translate[j]] = 1;
  954. X        else
  955. X          fastmap[j] = 1;
  956. X          }
  957. X      break;
  958. X
  959. X    case charset_not:
  960. X      /* Chars beyond end of map must be allowed */
  961. X      for (j = *p * BYTEWIDTH; j < (1 << BYTEWIDTH); j++)
  962. X        if (translate)
  963. X          fastmap[translate[j]] = 1;
  964. X        else
  965. X          fastmap[j] = 1;
  966. X
  967. X      for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--)
  968. X        if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))))
  969. X          {
  970. X        if (translate)
  971. X          fastmap[translate[j]] = 1;
  972. X        else
  973. X          fastmap[j] = 1;
  974. X          }
  975. X      break;
  976. X    }
  977. X
  978. X      /* Get here means we have successfully found the possible starting characters
  979. X     of one path of the pattern.  We need not follow this path any farther.
  980. X     Instead, look at the next alternative remembered in the stack. */
  981. X      if (stackp != stackb)
  982. X    p = *stackp--;
  983. X      else
  984. X    break;
  985. X    }
  986. X}
  987. X
  988. X/* Like re_search_2, below, but only one string is specified. */
  989. X
  990. Xint
  991. Xre_search (pbufp, string, size, startpos, range, regs)
  992. X     struct re_pattern_buffer *pbufp;
  993. X     char *string;
  994. X     int size, startpos, range;
  995. X     struct re_registers *regs;
  996. X{
  997. X  return re_search_2 (pbufp, 0, 0, string, size, startpos, range, regs, size);
  998. X}
  999. X
  1000. X/* Like re_match_2 but tries first a match starting at index STARTPOS,
  1001. X   then at STARTPOS + 1, and so on.
  1002. X   RANGE is the number of places to try before giving up.
  1003. X   If RANGE is negative, the starting positions tried are
  1004. X    STARTPOS, STARTPOS - 1, etc.
  1005. X   It is up to the caller to make sure that range is not so large
  1006. X   as to take the starting position outside of the input strings.
  1007. X
  1008. XThe value returned is the position at which the match was found,
  1009. X or -1 if no match was found,
  1010. X or -2 if error (such as failure stack overflow).  */
  1011. X
  1012. Xint
  1013. Xre_search_2 (pbufp, string1, size1, string2, size2, startpos, range, regs, mstop)
  1014. X     struct re_pattern_buffer *pbufp;
  1015. X     char *string1, *string2;
  1016. X     int size1, size2;
  1017. X     int startpos;
  1018. X     register int range;
  1019. X     struct re_registers *regs;
  1020. X     int mstop;
  1021. X{
  1022. X  register char *fastmap = pbufp->fastmap;
  1023. X  register unsigned char *translate = (unsigned char *) pbufp->translate;
  1024. X  int total = size1 + size2;
  1025. X  int val;
  1026. X
  1027. X  /* Update the fastmap now if not correct already */
  1028. X  if (fastmap && !pbufp->fastmap_accurate)
  1029. X    re_compile_fastmap (pbufp);
  1030. X  
  1031. X  /* Don't waste time in a long search for a pattern
  1032. X     that says it is anchored.  */
  1033. X  if (pbufp->used > 0 && (enum regexpcode) pbufp->buffer[0] == begbuf
  1034. X      && range > 0)
  1035. X    {
  1036. X      if (startpos > 0)
  1037. X    return -1;
  1038. X      else
  1039. X    range = 1;
  1040. X    }
  1041. X
  1042. X  while (1)
  1043. X    {
  1044. X      /* If a fastmap is supplied, skip quickly over characters
  1045. X     that cannot possibly be the start of a match.
  1046. X     Note, however, that if the pattern can possibly match
  1047. X     the null string, we must test it at each starting point
  1048. X     so that we take the first null string we get.  */
  1049. X
  1050. X      if (fastmap && startpos < total && pbufp->can_be_null != 1)
  1051. X    {
  1052. X      if (range > 0)
  1053. X        {
  1054. X          register int lim = 0;
  1055. X          register unsigned char *p;
  1056. X          int irange = range;
  1057. X          if (startpos < size1 && startpos + range >= size1)
  1058. X        lim = range - (size1 - startpos);
  1059. X
  1060. X          p = ((unsigned char *)
  1061. X           &(startpos >= size1 ? string2 - size1 : string1)[startpos]);
  1062. X
  1063. X          if (translate)
  1064. X        {
  1065. X          while (range > lim && !fastmap[translate[*p++]])
  1066. X            range--;
  1067. X        }
  1068. X          else
  1069. X        {
  1070. X          while (range > lim && !fastmap[*p++])
  1071. X            range--;
  1072. X        }
  1073. X          startpos += irange - range;
  1074. X        }
  1075. X      else
  1076. X        {
  1077. X          register unsigned char c;
  1078. X          if (startpos >= size1)
  1079. X        c = string2[startpos - size1];
  1080. X          else
  1081. X        c = string1[startpos];
  1082. X          c &= 0xff;
  1083. X          if (translate ? !fastmap[translate[c]] : !fastmap[c])
  1084. X        goto advance;
  1085. X        }
  1086. X    }
  1087. X
  1088. X      if (range >= 0 && startpos == total
  1089. X      && fastmap && pbufp->can_be_null == 0)
  1090. X    return -1;
  1091. X
  1092. X      val = re_match_2 (pbufp, string1, size1, string2, size2, startpos, regs, mstop);
  1093. X      if (0 <= val)
  1094. X    {
  1095. X      if (val == -2)
  1096. X        return -2;
  1097. X      return startpos;
  1098. X    }
  1099. X
  1100. X#ifdef C_ALLOCA
  1101. X      alloca (0);
  1102. X#endif /* C_ALLOCA */
  1103. X
  1104. X    advance:
  1105. X      if (!range) break;
  1106. X      if (range > 0) range--, startpos++; else range++, startpos--;
  1107. X    }
  1108. X  return -1;
  1109. X}
  1110. X
  1111. X#ifndef emacs   /* emacs never uses this */
  1112. Xint
  1113. Xre_match (pbufp, string, size, pos, regs)
  1114. X     struct re_pattern_buffer *pbufp;
  1115. X     char *string;
  1116. X     int size, pos;
  1117. X     struct re_registers *regs;
  1118. X{
  1119. X  return re_match_2 (pbufp, 0, 0, string, size, pos, regs, size);
  1120. X}
  1121. X#endif /* emacs */
  1122. X
  1123. X/* Maximum size of failure stack.  Beyond this, overflow is an error.  */
  1124. X
  1125. Xint re_max_failures = 2000;
  1126. X
  1127. Xstatic int bcmp_translate();
  1128. X/* Match the pattern described by PBUFP
  1129. X   against data which is the virtual concatenation of STRING1 and STRING2.
  1130. X   SIZE1 and SIZE2 are the sizes of the two data strings.
  1131. X   Start the match at position POS.
  1132. X   Do not consider matching past the position MSTOP.
  1133. X
  1134. X   If pbufp->fastmap is nonzero, then it had better be up to date.
  1135. X
  1136. X   The reason that the data to match are specified as two components
  1137. X   which are to be regarded as concatenated
  1138. X   is so this function can be used directly on the contents of an Emacs buffer.
  1139. X
  1140. X   -1 is returned if there is no match.  -2 is returned if there is
  1141. X   an error (such as match stack overflow).  Otherwise the value is the length
  1142. X   of the substring which was matched.  */
  1143. X
  1144. Xint
  1145. Xre_match_2 (pbufp, string1, size1, string2, size2, pos, regs, mstop)
  1146. X     struct re_pattern_buffer *pbufp;
  1147. X     unsigned char *string1, *string2;
  1148. X     int size1, size2;
  1149. X     int pos;
  1150. X     struct re_registers *regs;
  1151. X     int mstop;
  1152. X{
  1153. X  register unsigned char *p = (unsigned char *) pbufp->buffer;
  1154. X  register unsigned char *pend = p + pbufp->used;
  1155. X  /* End of first string */
  1156. X  unsigned char *end1;
  1157. X  /* End of second string */
  1158. X  unsigned char *end2;
  1159. X  /* Pointer just past last char to consider matching */
  1160. X  unsigned char *end_match_1, *end_match_2;
  1161. X  register unsigned char *d, *dend;
  1162. X  register int mcnt;
  1163. X  unsigned char *translate = (unsigned char *) pbufp->translate;
  1164. X
  1165. X /* Failure point stack.  Each place that can handle a failure further down the line
  1166. X    pushes a failure point on this stack.  It consists of two char *'s.
  1167. X    The first one pushed is where to resume scanning the pattern;
  1168. X    the second pushed is where to resume scanning the strings.
  1169. X    If the latter is zero, the failure point is a "dummy".
  1170. X    If a failure happens and the innermost failure point is dormant,
  1171. X    it discards that failure point and tries the next one. */
  1172. X
  1173. X  unsigned char *initial_stack[2 * NFAILURES];
  1174. X  unsigned char **stackb = initial_stack;
  1175. X  unsigned char **stackp = stackb, **stacke = &stackb[2 * NFAILURES];
  1176. X
  1177. X  /* Information on the "contents" of registers.
  1178. X     These are pointers into the input strings; they record
  1179. X     just what was matched (on this attempt) by some part of the pattern.
  1180. X     The start_memory command stores the start of a register's contents
  1181. X     and the stop_memory command stores the end.
  1182. X
  1183. X     At that point, regstart[regnum] points to the first character in the register,
  1184. X     regend[regnum] points to the first character beyond the end of the register,
  1185. X     regstart_seg1[regnum] is true iff regstart[regnum] points into string1,
  1186. X     and regend_seg1[regnum] is true iff regend[regnum] points into string1.  */
  1187. X
  1188. X  unsigned char *regstart[RE_NREGS];
  1189. X  unsigned char *regend[RE_NREGS];
  1190. X  unsigned char regstart_seg1[RE_NREGS], regend_seg1[RE_NREGS];
  1191. X
  1192. X  /* Set up pointers to ends of strings.
  1193. X     Don't allow the second string to be empty unless both are empty.  */
  1194. X  if (!size2)
  1195. X    {
  1196. X      string2 = string1;
  1197. X      size2 = size1;
  1198. X      string1 = 0;
  1199. X      size1 = 0;
  1200. X    }
  1201. X  end1 = string1 + size1;
  1202. X  end2 = string2 + size2;
  1203. X
  1204. X  /* Compute where to stop matching, within the two strings */
  1205. X  if (mstop <= size1)
  1206. X    {
  1207. X      end_match_1 = string1 + mstop;
  1208. X      end_match_2 = string2;
  1209. X    }
  1210. X  else
  1211. X    {
  1212. X      end_match_1 = end1;
  1213. X      end_match_2 = string2 + mstop - size1;
  1214. X    }
  1215. X
  1216. X  /* Initialize \) text positions to -1
  1217. X     to mark ones that no \( or \) has been seen for.  */
  1218. X
  1219. X  for (mcnt = 0; mcnt < sizeof (regend) / sizeof (*regend); mcnt++)
  1220. X    regend[mcnt] = (unsigned char *) -1;
  1221. X
  1222. X  /* `p' scans through the pattern as `d' scans through the data.
  1223. X     `dend' is the end of the input string that `d' points within.
  1224. X     `d' is advanced into the following input string whenever necessary,
  1225. X     but this happens before fetching;
  1226. X     therefore, at the beginning of the loop,
  1227. X     `d' can be pointing at the end of a string,
  1228. X     but it cannot equal string2.  */
  1229. X
  1230. X  if (pos <= size1)
  1231. X    d = string1 + pos, dend = end_match_1;
  1232. X  else
  1233. X    d = string2 + pos - size1, dend = end_match_2;
  1234. X
  1235. X/* Write PREFETCH; just before fetching a character with *d.  */
  1236. X#define PREFETCH \
  1237. X while (d == dend)                            \
  1238. X  { if (dend == end_match_2) goto fail;  /* end of string2 => failure */   \
  1239. X    d = string2;  /* end of string1 => advance to string2. */       \
  1240. X    dend = end_match_2; }
  1241. X
  1242. X  /* This loop loops over pattern commands.
  1243. X     It exits by returning from the function if match is complete,
  1244. X     or it drops through if match fails at this starting point in the input data. */
  1245. X
  1246. X  while (1)
  1247. X    {
  1248. X      if (p == pend)
  1249. X    /* End of pattern means we have succeeded! */
  1250. X    {
  1251. X      /* If caller wants register contents data back, convert it to indices */
  1252. X      if (regs)
  1253. X        {
  1254. X           regs->start[0] = pos;
  1255. X           if (dend == end_match_1)
  1256. X         regs->end[0] = d - string1;
  1257. X           else
  1258. X         regs->end[0] = d - string2 + size1;
  1259. X           for (mcnt = 1; mcnt < RE_NREGS; mcnt++)
  1260. X        {
  1261. X          if (regend[mcnt] == (unsigned char *) -1)
  1262. X            {
  1263. X              regs->start[mcnt] = -1;
  1264. X              regs->end[mcnt] = -1;
  1265. X              continue;
  1266. X            }
  1267. X           if (regstart_seg1[mcnt])
  1268. X            regs->start[mcnt] = regstart[mcnt] - string1;
  1269. X          else
  1270. X            regs->start[mcnt] = regstart[mcnt] - string2 + size1;
  1271. X           if (regend_seg1[mcnt])
  1272. X            regs->end[mcnt] = regend[mcnt] - string1;
  1273. X          else
  1274. X            regs->end[mcnt] = regend[mcnt] - string2 + size1;
  1275. X        }
  1276. X        }
  1277. X       if (dend == end_match_1)
  1278. X        return (d - string1 - pos);
  1279. X      else
  1280. X        return d - string2 + size1 - pos;
  1281. X    }
  1282. X
  1283. X      /* Otherwise match next pattern command */
  1284. X#ifdef SWITCH_ENUM_BUG
  1285. X      switch ((int) ((enum regexpcode) *p++))
  1286. X#else
  1287. X      switch ((enum regexpcode) *p++)
  1288. X#endif
  1289. X    {
  1290. X
  1291. X    /* \( is represented by a start_memory, \) by a stop_memory.
  1292. X        Both of those commands contain a "register number" argument.
  1293. X        The text matched within the \( and \) is recorded under that number.
  1294. X        Then, \<digit> turns into a `duplicate' command which
  1295. X        is followed by the numeric value of <digit> as the register number. */
  1296. X
  1297. X    case start_memory:
  1298. X      regstart[*p] = d;
  1299. X       regstart_seg1[*p++] = (dend == end_match_1);
  1300. X      break;
  1301. X
  1302. X    case stop_memory:
  1303. X      regend[*p] = d;
  1304. X       regend_seg1[*p++] = (dend == end_match_1);
  1305. X      break;
  1306. X
  1307. X    case duplicate:
  1308. X      {
  1309. X        int regno = *p++;   /* Get which register to match against */
  1310. X        register unsigned char *d2, *dend2;
  1311. X
  1312. X        d2 = regstart[regno];
  1313. X         dend2 = ((regstart_seg1[regno] == regend_seg1[regno])
  1314. X             ? regend[regno] : end_match_1);
  1315. X        while (1)
  1316. X          {
  1317. X        /* Advance to next segment in register contents, if necessary */
  1318. X        while (d2 == dend2)
  1319. X          {
  1320. X            if (dend2 == end_match_2) break;
  1321. X            if (dend2 == regend[regno]) break;
  1322. X            d2 = string2, dend2 = regend[regno];  /* end of string1 => advance to string2. */
  1323. X          }
  1324. X        /* At end of register contents => success */
  1325. X        if (d2 == dend2) break;
  1326. X
  1327. X        /* Advance to next segment in data being matched, if necessary */
  1328. X        PREFETCH;
  1329. X
  1330. X        /* mcnt gets # consecutive chars to compare */
  1331. X        mcnt = dend - d;
  1332. X        if (mcnt > dend2 - d2)
  1333. X          mcnt = dend2 - d2;
  1334. X        /* Compare that many; failure if mismatch, else skip them. */
  1335. X        if (translate ? bcmp_translate (d, d2, mcnt, translate) : bcmp (d, d2, mcnt))
  1336. X          goto fail;
  1337. X        d += mcnt, d2 += mcnt;
  1338. X          }
  1339. X      }
  1340. X      break;
  1341. X
  1342. X    case anychar:
  1343. X      /* fetch a data character */
  1344. X      PREFETCH;
  1345. X      /* Match anything but a newline.  */
  1346. X      if ((translate ? translate[*d++] : *d++) == '\n')
  1347. X        goto fail;
  1348. X      break;
  1349. X
  1350. X    case charset:
  1351. X    case charset_not:
  1352. X      {
  1353. X        /* Nonzero for charset_not */
  1354. X        int not = 0;
  1355. X        register int c;
  1356. X        if (*(p - 1) == (unsigned char) charset_not)
  1357. X          not = 1;
  1358. X
  1359. X        /* fetch a data character */
  1360. X        PREFETCH;
  1361. X
  1362. X        if (translate)
  1363. X          c = translate [*d];
  1364. X        else
  1365. X          c = *d;
  1366. X
  1367. X        if (c < *p * BYTEWIDTH
  1368. X        && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH)))
  1369. X          not = !not;
  1370. X
  1371. X        p += 1 + *p;
  1372. X
  1373. X        if (!not) goto fail;
  1374. X        d++;
  1375. X        break;
  1376. X      }
  1377. X
  1378. X    case begline:
  1379. X      if (d == string1 || d[-1] == '\n')
  1380. X        break;
  1381. X      goto fail;
  1382. X
  1383. X    case endline:
  1384. X      if (d == end2
  1385. X          || (d == end1 ? (size2 == 0 || *string2 == '\n') : *d == '\n'))
  1386. X        break;
  1387. X      goto fail;
  1388. X
  1389. X    /* "or" constructs ("|") are handled by starting each alternative
  1390. X        with an on_failure_jump that points to the start of the next alternative.
  1391. X        Each alternative except the last ends with a jump to the joining point.
  1392. X        (Actually, each jump except for the last one really jumps
  1393. X         to the following jump, because tensioning the jumps is a hassle.) */
  1394. X
  1395. X    /* The start of a stupid repeat has an on_failure_jump that points
  1396. X       past the end of the repeat text.
  1397. X       This makes a failure point so that, on failure to match a repetition,
  1398. X       matching restarts past as many repetitions have been found
  1399. X       with no way to fail and look for another one.  */
  1400. X
  1401. X    /* A smart repeat is similar but loops back to the on_failure_jump
  1402. X       so that each repetition makes another failure point. */
  1403. X
  1404. X    case on_failure_jump:
  1405. X      if (stackp == stacke)
  1406. X        {
  1407. X          unsigned char **stackx;
  1408. X          if (stacke - stackb > re_max_failures * 2)
  1409. X        return -2;
  1410. X          stackx = (unsigned char **) alloca (2 * (stacke - stackb)
  1411. X                     * sizeof (char *));
  1412. X          bcopy (stackb, stackx, (stacke - stackb) * sizeof (char *));
  1413. X          stackp = stackx + (stackp - stackb);
  1414. X          stacke = stackx + 2 * (stacke - stackb);
  1415. X          stackb = stackx;
  1416. X        }
  1417. X      mcnt = *p++ & 0377;
  1418. X      mcnt += SIGN_EXTEND_CHAR (*(char *)p) << 8;
  1419. X      p++;
  1420. X      *stackp++ = mcnt + p;
  1421. X      *stackp++ = d;
  1422. X      break;
  1423. X
  1424. X    /* The end of a smart repeat has an maybe_finalize_jump back.
  1425. X       Change it either to a finalize_jump or an ordinary jump. */
  1426. X
  1427. X    case maybe_finalize_jump:
  1428. X      mcnt = *p++ & 0377;
  1429. X      mcnt += SIGN_EXTEND_CHAR (*(char *)p) << 8;
  1430. X      p++;
  1431. X      {
  1432. X        register unsigned char *p2 = p;
  1433. X        /* Compare what follows with the begining of the repeat.
  1434. X           If we can establish that there is nothing that they would
  1435. X           both match, we can change to finalize_jump */
  1436. X        while (p2 != pend
  1437. X           && (*p2 == (unsigned char) stop_memory
  1438. X               || *p2 == (unsigned char) start_memory))
  1439. X          p2++;
  1440. X        if (p2 == pend)
  1441. X          p[-3] = (unsigned char) finalize_jump;
  1442. X        else if (*p2 == (unsigned char) exactn
  1443. X             || *p2 == (unsigned char) endline)
  1444. X          {
  1445. X        register int c = *p2 == (unsigned char) endline ? '\n' : p2[2];
  1446. X        register unsigned char *p1 = p + mcnt;
  1447. X        /* p1[0] ... p1[2] are an on_failure_jump.
  1448. X           Examine what follows that */
  1449. X        if (p1[3] == (unsigned char) exactn && p1[5] != c)
  1450. X          p[-3] = (unsigned char) finalize_jump;
  1451. X        else if (p1[3] == (unsigned char) charset
  1452. X             || p1[3] == (unsigned char) charset_not)
  1453. X          {
  1454. X            int not = p1[3] == (unsigned char) charset_not;
  1455. X            if (c < p1[4] * BYTEWIDTH
  1456. X            && p1[5 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH)))
  1457. X              not = !not;
  1458. X            /* not is 1 if c would match */
  1459. X            /* That means it is not safe to finalize */
  1460. X            if (!not)
  1461. X              p[-3] = (unsigned char) finalize_jump;
  1462. X          }
  1463. X          }
  1464. X      }
  1465. X      p -= 2;
  1466. X      if (p[-1] != (unsigned char) finalize_jump)
  1467. X        {
  1468. X          p[-1] = (unsigned char) jump;
  1469. X          goto nofinalize;
  1470. X        }
  1471. X
  1472. X    /* The end of a stupid repeat has a finalize-jump
  1473. X       back to the start, where another failure point will be made
  1474. X       which will point after all the repetitions found so far. */
  1475. X
  1476. X    case finalize_jump:
  1477. X      stackp -= 2;
  1478. X
  1479. X    case jump:
  1480. X    nofinalize:
  1481. X      mcnt = *p++ & 0377;
  1482. X      mcnt += SIGN_EXTEND_CHAR (*(char *)p) << 8;
  1483. X      p += mcnt + 1;    /* The 1 compensates for missing ++ above */
  1484. X      break;
  1485. X
  1486. X    case dummy_failure_jump:
  1487. X      if (stackp == stacke)
  1488. X        {
  1489. X          unsigned char **stackx
  1490. X        = (unsigned char **) alloca (2 * (stacke - stackb)
  1491. X                         * sizeof (char *));
  1492. X          bcopy (stackb, stackx, (stacke - stackb) * sizeof (char *));
  1493. X          stackp = stackx + (stackp - stackb);
  1494. X          stacke = stackx + 2 * (stacke - stackb);
  1495. X          stackb = stackx;
  1496. X        }
  1497. X      *stackp++ = 0;
  1498. X      *stackp++ = 0;
  1499. X      goto nofinalize;
  1500. X
  1501. X    case wordbound:
  1502. X      if (d == string1  /* Points to first char */
  1503. X          || d == end2  /* Points to end */
  1504. X          || (d == end1 && size2 == 0)) /* Points to end */
  1505. X        break;
  1506. X      if ((SYNTAX (d[-1]) == Sword)
  1507. X          != (SYNTAX (d == end1 ? *string2 : *d) == Sword))
  1508. X        break;
  1509. X      goto fail;
  1510. X
  1511. X    case notwordbound:
  1512. X      if (d == string1  /* Points to first char */
  1513. X          || d == end2  /* Points to end */
  1514. X          || (d == end1 && size2 == 0)) /* Points to end */
  1515. X        goto fail;
  1516. X      if ((SYNTAX (d[-1]) == Sword)
  1517. X          != (SYNTAX (d == end1 ? *string2 : *d) == Sword))
  1518. X        goto fail;
  1519. X      break;
  1520. X
  1521. X    case wordbeg:
  1522. X      if (d == end2  /* Points to end */
  1523. X          || (d == end1 && size2 == 0) /* Points to end */
  1524. X          || SYNTAX (* (d == end1 ? string2 : d)) != Sword) /* Next char not a letter */
  1525. X        goto fail;
  1526. X      if (d == string1  /* Points to first char */
  1527. X          || SYNTAX (d[-1]) != Sword)  /* prev char not letter */
  1528. X        break;
  1529. X      goto fail;
  1530. X
  1531. X    case wordend:
  1532. X      if (d == string1  /* Points to first char */
  1533. X          || SYNTAX (d[-1]) != Sword)  /* prev char not letter */
  1534. X        goto fail;
  1535. X      if (d == end2  /* Points to end */
  1536. X          || (d == end1 && size2 == 0) /* Points to end */
  1537. X          || SYNTAX (d == end1 ? *string2 : *d) != Sword) /* Next char not a letter */
  1538. X        break;
  1539. X      goto fail;
  1540. X
  1541. X#ifdef emacs
  1542. X    case before_dot:
  1543. X      if (((d - string2 <= (unsigned) size2)
  1544. X           ? d - bf_p2 : d - bf_p1)
  1545. X          <= point)
  1546. X        goto fail;
  1547. X      break;
  1548. X
  1549. X    case at_dot:
  1550. X      if (((d - string2 <= (unsigned) size2)
  1551. X           ? d - bf_p2 : d - bf_p1)
  1552. X          == point)
  1553. X        goto fail;
  1554. X      break;
  1555. X
  1556. X    case after_dot:
  1557. X      if (((d - string2 <= (unsigned) size2)
  1558. X           ? d - bf_p2 : d - bf_p1)
  1559. X          >= point)
  1560. X        goto fail;
  1561. X      break;
  1562. X
  1563. X    case wordchar:
  1564. X      mcnt = (int) Sword;
  1565. X      goto matchsyntax;
  1566. X
  1567. X    case syntaxspec:
  1568. X      mcnt = *p++;
  1569. X    matchsyntax:
  1570. X      PREFETCH;
  1571. X      if (SYNTAX (*d++) != (enum syntaxcode) mcnt) goto fail;
  1572. X      break;
  1573. X      
  1574. X    case notwordchar:
  1575. X      mcnt = (int) Sword;
  1576. X      goto matchnotsyntax;
  1577. X
  1578. X    case notsyntaxspec:
  1579. X      mcnt = *p++;
  1580. X    matchnotsyntax:
  1581. X      PREFETCH;
  1582. X      if (SYNTAX (*d++) == (enum syntaxcode) mcnt) goto fail;
  1583. X      break;
  1584. X#else
  1585. X    case wordchar:
  1586. X      PREFETCH;
  1587. X      if (SYNTAX (*d++) == 0) goto fail;
  1588. X      break;
  1589. X      
  1590. X    case notwordchar:
  1591. X      PREFETCH;
  1592. X      if (SYNTAX (*d++) != 0) goto fail;
  1593. X      break;
  1594. X#endif /* not emacs */
  1595. X
  1596. X    case begbuf:
  1597. X      if (d == string1)    /* Note, d cannot equal string2 */
  1598. X        break;        /* unless string1 == string2.  */
  1599. X      goto fail;
  1600. X
  1601. X    case endbuf:
  1602. X      if (d == end2 || (d == end1 && size2 == 0))
  1603. X        break;
  1604. X      goto fail;
  1605. X
  1606. X    case exactn:
  1607. X      /* Match the next few pattern characters exactly.
  1608. X         mcnt is how many characters to match. */
  1609. X      mcnt = *p++;
  1610. X      if (translate)
  1611. X        {
  1612. X          do
  1613. X        {
  1614. X          PREFETCH;
  1615. X          if (translate[*d++] != *p++) goto fail;
  1616. X        }
  1617. X          while (--mcnt);
  1618. X        }
  1619. X      else
  1620. X        {
  1621. X          do
  1622. X        {
  1623. X          PREFETCH;
  1624. X          if (*d++ != *p++) goto fail;
  1625. X        }
  1626. X          while (--mcnt);
  1627. X        }
  1628. X      break;
  1629. X    }
  1630. X      continue;    /* Successfully matched one pattern command; keep matching */
  1631. X
  1632. X      /* Jump here if any matching operation fails. */
  1633. X    fail:
  1634. X      if (stackp != stackb)
  1635. X    /* A restart point is known.  Restart there and pop it. */
  1636. X    {
  1637. X      if (!stackp[-2])
  1638. X        {   /* If innermost failure point is dormant, flush it and keep looking */
  1639. X          stackp -= 2;
  1640. X          goto fail;
  1641. X        }
  1642. X      d = *--stackp;
  1643. X      p = *--stackp;
  1644. X      if (d >= string1 && d <= end1)
  1645. X        dend = end_match_1;
  1646. X    }
  1647. X      else break;   /* Matching at this starting point really fails! */
  1648. X    }
  1649. X  return -1;         /* Failure to match */
  1650. X}
  1651. X
  1652. Xstatic int
  1653. Xbcmp_translate (s1, s2, len, translate)
  1654. X     unsigned char *s1, *s2;
  1655. X     register int len;
  1656. X     unsigned char *translate;
  1657. X{
  1658. X  register unsigned char *p1 = s1, *p2 = s2;
  1659. X  while (len)
  1660. X    {
  1661. X      if (translate [*p1++] != translate [*p2++]) return 1;
  1662. X      len--;
  1663. X    }
  1664. X  return 0;
  1665. X}
  1666. X
  1667. X/* Entry points compatible with bsd4.2 regex library */
  1668. X
  1669. X#ifndef emacs
  1670. X
  1671. Xstatic struct re_pattern_buffer re_comp_buf;
  1672. X
  1673. Xchar *
  1674. Xre_comp (s)
  1675. X     char *s;
  1676. X{
  1677. X  if (!s)
  1678. X    {
  1679. X      if (!re_comp_buf.buffer)
  1680. X    return "No previous regular expression";
  1681. X      return 0;
  1682. X    }
  1683. X
  1684. X  if (!re_comp_buf.buffer)
  1685. X    {
  1686. X      if (!(re_comp_buf.buffer = (char *) malloc (200)))
  1687. X    return "Memory exhausted";
  1688. X      re_comp_buf.allocated = 200;
  1689. X      if (!(re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH)))
  1690. X    return "Memory exhausted";
  1691. X    }
  1692. X  return re_compile_pattern (s, strlen (s), &re_comp_buf);
  1693. X}
  1694. X
  1695. Xint
  1696. Xre_exec (s)
  1697. X     char *s;
  1698. X{
  1699. X  int len = strlen (s);
  1700. X  return 0 <= re_search (&re_comp_buf, s, len, 0, len, 0);
  1701. X}
  1702. X
  1703. X#endif /* emacs */
  1704. X
  1705. X#ifdef test
  1706. X
  1707. X#include <stdio.h>
  1708. X
  1709. X/* Indexed by a character, gives the upper case equivalent of the character */
  1710. X
  1711. Xstatic char upcase[0400] = 
  1712. X  { 000, 001, 002, 003, 004, 005, 006, 007,
  1713. X    010, 011, 012, 013, 014, 015, 016, 017,
  1714. X    020, 021, 022, 023, 024, 025, 026, 027,
  1715. X    030, 031, 032, 033, 034, 035, 036, 037,
  1716. X    040, 041, 042, 043, 044, 045, 046, 047,
  1717. X    050, 051, 052, 053, 054, 055, 056, 057,
  1718. X    060, 061, 062, 063, 064, 065, 066, 067,
  1719. X    070, 071, 072, 073, 074, 075, 076, 077,
  1720. X    0100, 0101, 0102, 0103, 0104, 0105, 0106, 0107,
  1721. X    0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117,
  1722. X    0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
  1723. X    0130, 0131, 0132, 0133, 0134, 0135, 0136, 0137,
  1724. X    0140, 0101, 0102, 0103, 0104, 0105, 0106, 0107,
  1725. X    0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117,
  1726. X    0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
  1727. X    0130, 0131, 0132, 0173, 0174, 0175, 0176, 0177,
  1728. X    0200, 0201, 0202, 0203, 0204, 0205, 0206, 0207,
  1729. X    0210, 0211, 0212, 0213, 0214, 0215, 0216, 0217,
  1730. X    0220, 0221, 0222, 0223, 0224, 0225, 0226, 0227,
  1731. X    0230, 0231, 0232, 0233, 0234, 0235, 0236, 0237,
  1732. X    0240, 0241, 0242, 0243, 0244, 0245, 0246, 0247,
  1733. X    0250, 0251, 0252, 0253, 0254, 0255, 0256, 0257,
  1734. X    0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267,
  1735. X    0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277,
  1736. X    0300, 0301, 0302, 0303, 0304, 0305, 0306, 0307,
  1737. X    0310, 0311, 0312, 0313, 0314, 0315, 0316, 0317,
  1738. X    0320, 0321, 0322, 0323, 0324, 0325, 0326, 0327,
  1739. X    0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337,
  1740. X    0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347,
  1741. X    0350, 0351, 0352, 0353, 0354, 0355, 0356, 0357,
  1742. X    0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367,
  1743. X    0370, 0371, 0372, 0373, 0374, 0375, 0376, 0377
  1744. X  };
  1745. X
  1746. Xmain (argc, argv)
  1747. X     int argc;
  1748. X     char **argv;
  1749. X{
  1750. X  char pat[80];
  1751. X  struct re_pattern_buffer buf;
  1752. X  int i;
  1753. X  char c;
  1754. X  char fastmap[(1 << BYTEWIDTH)];
  1755. X
  1756. X  /* Allow a command argument to specify the style of syntax.  */
  1757. X  if (argc > 1)
  1758. X    obscure_syntax = atoi (argv[1]);
  1759. X
  1760. X  buf.allocated = 40;
  1761. X  buf.buffer = (char *) malloc (buf.allocated);
  1762. X  buf.fastmap = fastmap;
  1763. X  buf.translate = upcase;
  1764. X
  1765. X  while (1)
  1766. X    {
  1767. X      gets (pat);
  1768. X
  1769. X      if (*pat)
  1770. X    {
  1771. X          re_compile_pattern (pat, strlen(pat), &buf);
  1772. X
  1773. X      for (i = 0; i < buf.used; i++)
  1774. X        printchar (buf.buffer[i]);
  1775. X
  1776. X      putchar ('\n');
  1777. X
  1778. X      printf ("%d allocated, %d used.\n", buf.allocated, buf.used);
  1779. X
  1780. X      re_compile_fastmap (&buf);
  1781. X      printf ("Allowed by fastmap: ");
  1782. X      for (i = 0; i < (1 << BYTEWIDTH); i++)
  1783. X        if (fastmap[i]) printchar (i);
  1784. X      putchar ('\n');
  1785. X    }
  1786. X
  1787. X      gets (pat);    /* Now read the string to match against */
  1788. X
  1789. X      i = re_match (&buf, pat, strlen (pat), 0, 0);
  1790. X      printf ("Match value %d.\n", i);
  1791. X    }
  1792. X}
  1793. X
  1794. X#ifdef NOTDEF
  1795. Xprint_buf (bufp)
  1796. X     struct re_pattern_buffer *bufp;
  1797. X{
  1798. X  int i;
  1799. X
  1800. X  printf ("buf is :\n----------------\n");
  1801. X  for (i = 0; i < bufp->used; i++)
  1802. X    printchar (bufp->buffer[i]);
  1803. X  
  1804. X  printf ("\n%d allocated, %d used.\n", bufp->allocated, bufp->used);
  1805. X  
  1806. X  printf ("Allowed by fastmap: ");
  1807. X  for (i = 0; i < (1 << BYTEWIDTH); i++)
  1808. X    if (bufp->fastmap[i])
  1809. X      printchar (i);
  1810. X  printf ("\nAllowed by translate: ");
  1811. X  if (bufp->translate)
  1812. X    for (i = 0; i < (1 << BYTEWIDTH); i++)
  1813. X      if (bufp->translate[i])
  1814. X    printchar (i);
  1815. X  printf ("\nfastmap is%s accurate\n", bufp->fastmap_accurate ? "" : "n't");
  1816. X  printf ("can %s be null\n----------", bufp->can_be_null ? "" : "not");
  1817. X}
  1818. X#endif
  1819. X
  1820. Xprintchar (c)
  1821. X     char c;
  1822. X{
  1823. X  if (c < 041 || c >= 0177)
  1824. X    {
  1825. X      putchar ('\\');
  1826. X      putchar (((c >> 6) & 3) + '0');
  1827. X      putchar (((c >> 3) & 7) + '0');
  1828. X      putchar ((c & 7) + '0');
  1829. X    }
  1830. X  else
  1831. X    putchar (c);
  1832. X}
  1833. X
  1834. Xerror (string)
  1835. X     char *string;
  1836. X{
  1837. X  puts (string);
  1838. X  exit (1);
  1839. X}
  1840. X
  1841. X#endif /* test */
  1842. END_OF_FILE
  1843. if test 49183 -ne `wc -c <'regex.c'`; then
  1844.     echo shar: \"'regex.c'\" unpacked with wrong size!
  1845. fi
  1846. # end of 'regex.c'
  1847. fi
  1848. echo shar: End of shell archive.
  1849. exit 0
  1850.  
  1851.